<template>
  <div class="api">
    <div>{{ 'width' }}</div>
  </div>
</template>
<script setup lang="ts">
import api from '@/api/index.js'
/* for (let i = 0; i < 100; i++) {
    // const element = array[i];
    api.getCurtemTime(Math.floor(Math.random() * 5000 + 5000)).then(res => {
        console.log(i, res);
    })
} */
const apiList = new Array(30).fill(null).map(() => {
  return {
    fun: api.getCurtemTime,
    params: Math.floor(Math.random() * 3000 + 1000),
  }
})
let task = 6
let i = 0
console.log(apiList)

const getData = () => {
  apiList[0]?.fun?.(apiList[0].params)?.then((res) => {
      console.log(i, res)
    })
    .catch(() => {
      console.log(i, 'error')
    })
    .finally(() => {
      i++
      if (apiList.length) {
        getData()
      }
    })
  apiList.shift()
}
while (task-- > 0) {
  getData()
}
</script>
<style lang="scss" scoped>
.api {
}
</style>
